program LelaranJacobi
implicit none
real*8 epsilon, x, y, answer
integer*2 count
parameter (epsilon = 1.E-6)
print*, "Enter koordinat starting values ..."
read*,x
read*,y
call jacobi(epsilon, x, y, count)
if (count > 100) then
   print*, "error not reached ... the method failed."
else
   print*, "After ", count, " iterations,"
   print*, "a zero was found at ", x,",",y
end if
end

subroutine ex(x,y)
implicit none
real*8 x,y
y = 1 + x + x**2/2 + x**3/6 + x**4/24
end

subroutine jacobi(eps, x, y,count)
implicit none
real*8 eps, x, y, x0, y0,error_x,error_y
integer*2 count
error_x = 1;
error_y = 1;
count=0
print*, count,"\t\t",x,"\t\t",y,"\t\t",error_x,"\t\t",error_y
do while (error_x > eps .OR. error_y > eps)
x0 = x
y0 = y
count = count+1
call fx(x0,y0,x)
call fy(x,y0,y)
error_x = abs(x-x0)
error_y = abs(y-y0) 
print*, count,"\t\t",x,"\t\t",y,"\t\t",error_x,"\t\t",error_y
end do
end

subroutine fx(x,y,z)
implicit none
real*8 x,y,z
z = sqrt(10-x*y)
end

subroutine fy(x,y,z)
implicit none
real*8 x,y,z
z = sqrt((57-y)/(3*x))
end
